package com.hospital.pet.love.lovepethospital.controller;

import com.hospital.pet.love.lovepethospital.dto.caze.*;
import com.hospital.pet.love.lovepethospital.resp.Result;
import com.hospital.pet.love.lovepethospital.resp.ResultCodeEnum;
import com.hospital.pet.love.lovepethospital.service.CaseService;
import com.hospital.pet.love.lovepethospital.util.RoleJudgeUtil;
import com.hospital.pet.love.lovepethospital.vo.caze.CaseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author RoselleShaw
 * @create 2024-04-26 15:59
 */
@RestController
@RequestMapping("/case")
@Tag(name = "病例管理")
public class CaseController {

    @Resource
    private CaseService caseService;

    @PostMapping("/get-consumer")
    @Operation(summary = "查询病例（客户）")
    public Result<List<CaseVo>> getConsumer(@RequestBody GetCaseConsumerDto getCaseConsumerDto) {
        List<CaseVo> cases = caseService.getConsumer(getCaseConsumerDto);
        return Result.build(cases, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/get-employee")
    @Operation(summary = "查询病例（员工）")
    public Result<List<CaseVo>> getEmployee(@RequestBody GetCaseEmployeeDto getCaseEmployeeDto) {
        List<CaseVo> cases = caseService.getEmployee(getCaseEmployeeDto);
        return Result.build(cases, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/add")
    @Operation(summary = "添加病例")
    public Result<Void> add(@RequestBody AddCaseDto addCaseDto) {
        caseService.add(addCaseDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/delete-by-id/{id}")
    @Operation(summary = "删除病例")
    public Result<Void> deleteById(@PathVariable Long id) {
        RoleJudgeUtil.employeeJudge();
        if (!caseService.removeById(id)) {
            return Result.build(null, ResultCodeEnum.CASE_NOT_EXIST);
        }
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/update-by-id")
    @Operation(summary = "修改病例")
    public Result<Void> updateById(@RequestBody UpdateCaseDto updateCaseDto) {
        caseService.updateById(updateCaseDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/pay/{id}")
    @Operation(summary = "支付")
    public Result<Void> pay(@PathVariable Integer id) {
        caseService.pay(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/export-data")
    @Operation(summary = "病例报表")
    public void exportData(@RequestBody CaseExportDto caseExportDto, HttpServletResponse response) {
        caseService.exportData(response, caseExportDto);
    }

}
